<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class teacher  extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
                public  $URL;
                public function __construct() {
                    parent::__construct();
                    $this->URL = $this->uri->uri_to_assoc();
                    $this->authen_model->CheckPermission();
                    $this->load->model("teacher_model");
                    $this->load->model("collegian_model");
                    
                }
                
	public function index()
	{
                      
	}
        
                public function add_teacher_data(){
                    $sql = "INSERT  INTO teachers (teacher_id , teacher_code,teacher_date,teacher_name,gender,teacher_phone,ref_major_id) 
                                VALUES(NULL , '$_POST[txt_code]' , '$_POST[year]-$_POST[month]-$_POST[day]' , 
                                    '$_POST[txt_name]' , '$_POST[gender]' , '$_POST[phone_number]' , '$_POST[group_type]'  
                                )
                                ";
                   $this->db->query($sql);
                        if($this->db->affected_rows() > 0){
                            print(
                                    '<query>
                                        <status  q="true"></status>
                                    </query>'
                                    );
                        }else{
                            print(
                                    '<query>
                                        <status  q="false"></status>
                                    </query>'
                                    );
                        }
                }
        
                public function add_teacher(){
                                $data["majors"] = $this->collegian_model->get_majors();
                                $this->templates
                                        ->appendJs("teacher.js")
                                        ->setContent($this->load->view("teacher/frm_teacher_create",$data,true))
                                        ->setTitle("เพิ่มข้อมูลอาจารย์")
                                        ->rander();
                }
        
                public function view_teacher(){
                        $this->load->model("collegian_model");
                        $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("teacher.js")
                                ->setContent($this->load->view("teacher/view_teachers",$data,true))
                                ->setTitle("แสดงข้อมูลอาจารย์")
                                ->rander();
                }
        
                public function teacher_activity(){
                        $data["teacher_activity"] =  $this->teacher_model->get_report($_SESSION["id"]);
                        
                        $this->templates
                                ->appendJs("teacher.js")
                                ->setContent($this->load->view("teacher/teacher_activity_report",$data,true))
                                ->setTitle("สร้างข้อมูลกิจกรรม")
                                ->rander();
                }
        
                public function get_teacher_dialog(){
                    $data["teacher_datay"] = $this->teacher_model->getTeacher();
                    $this->load->view("major/dialog_teacher_api",$data);
                }
                
                public function teacher_activity_display(){
                    if( $this->URL["ID"] != ""){
                        $data["teacher_activity"] = $this->teacher_model->get_teacher_activitys( $this->URL["ID"] );
                        $data["teacher_datay"] = $this->teacher_model->get_teacher_by_id(  $this->URL["ID"] );
                        $data["ID"] = $this->URL["ID"];
                        $this->templates
                                ->setContent($this->load->view("teacher/teacher_activity_report_sumary",$data,true))
                                ->setTitle("ข้อมูลกิจกรรม")
                                ->rander();
                    }
                }
                
                public function print_teacher_activity_display(){
                    if( $this->URL["ID"] != ""){
                        $data["teacher_activity"] = $this->teacher_model->get_teacher_activitys( $this->URL["ID"] );
                        $data["teacher_datay"] = $this->teacher_model->get_teacher_by_id(  $this->URL["ID"] );
                        $data["ID"] = $this->URL["ID"];
                        $this->load->view("teacher/print_teacher_activity_report_sumary",$data);
                    }
                }
                
                public function search_teachers(){
                    $data = array();
                    $keyword = mysql_escape_string($_POST["txt_search"]);
                    $major = mysql_escape_string($_POST["group_type"]);
                    $data["teachers_datay"] = $this->teacher_model->search_teacher($keyword,$major);
                    $data["count"] = $this->db_model->getCount();
                    $this->load->view("teacher/view_teachers_table",$data);
                }
                
                public function get_dialog_edit_teacher(){
                    $data["teachers_datay"] = $this->teacher_model->get_teacher_by_id($_POST["teacher_id"]);
                    $data["majors"] = $this->collegian_model->get_majors();
                    $this->load->view("teacher/dialog_edit_teacher",$data);
                }
                
                public function update_teacher(){
                    if(isset($_POST["teacher_id"])){
                        $this->teacher_model->update($_POST);
                    }
                }
        
               
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */